﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using FluentNHibernate.Mapping;

namespace Barry.BarbeSystem.Models
{



    public class Member
    {
        [Key]
        public virtual  int Id { set; get; }


        [Display(Name = "会员卡号")]
        [Required(ErrorMessage = "卡号不能为空！")]
        [MaxLength(20)]
        public virtual string CardId { set; get; }

        [Display(Name = "姓名")]
        [Required(ErrorMessage = "姓名不能为空！")]
        [MaxLength(10)]
        public virtual string Name { set; get; }

        [Display(Name = "联系电话")]
        [MaxLength(20)]
        public virtual string PhoneNumber { set; get; }

        [Display(Name = "余额")]
        [Required(ErrorMessage = "余额不能为空")]
        [Range(typeof(decimal), "0", "50000000", ErrorMessage = "金额必须大于等于0")]
        public virtual decimal Balance { set; get; }

        [Display(Name = "折扣")]
        [Range(typeof(decimal), "0", "10", ErrorMessage = "打折必须0~10之间")]
        public virtual decimal Discount { set; get; }



        [Display(Name = "备注")]
        public virtual string Remarks { set; get; }

        public virtual bool Enable { set; get; }

        [Display(Name = "充值金额")]
        [Required(ErrorMessage = "金额不能为空")]
        [Range(typeof(decimal), "0", "50000000", ErrorMessage = "金额必须大于等于0")]
        public virtual decimal RechargeNumber { set; get; }

        public override string ToString()
        {
            return  "卡号："+  CardId + " 姓名：" + Name + " 电话号码：" + PhoneNumber + " 余额：" + Balance + " 折扣：" + Discount + "  ";
        }
    }

    public class MemberMap : ClassMap<Member>
    {
        public MemberMap()
        {
            Id(i => i.Id);
            Map(i => i.Name).Length(10).Not.Nullable();
            Map(i => i.CardId).Length(20).Not.Nullable();
            Map(i => i.PhoneNumber).Length(20).Not.Nullable();
            Map(i => i.Balance).Precision(10).Scale(2).Not.Nullable();
            Map(i => i.Discount).Precision(4).Scale(2).Not.Nullable();
            Map(i => i.Remarks).Length(2000);
            Map(i => i.Enable).Default("1");
        }
    }


    public class MemberPageRequest:PageRequest
    {

        public string cardId { set; get; }

        public string name { set; get; }
    }
}